home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / FAQSYS18.ZIP / FAQS.DAT / OPT32.TXT < prev    next >
Encoding:
Text File  |  1996-06-02  |  75.7 KB  |  1,886 lines

  1. AP-500
  2.  
  3. Application
  4. Note
  5.  
  6.  
  7. Optimizations for Intel's 
  8. 32-Bit Processors
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. February 1994
  36.  
  37.  
  38.  
  39.  
  40.  
  41. The following are trademarks of Intel Corporation and may only be used to identify Intel products:
  42. Intel, Intel386, Intel486, i486, and Pentium
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. Intel Corporation makes no warranty for the use of its products and assumes no responsibility for any errors which may appear in this document nor does it make a commitment to update the information contained herein.
  75.  
  76. Intel retains the right to make changes to these specifications at any time, without notice.
  77.  
  78. Contact your local Intel sales office or your distributor to obtain the latest specifications before placing your product order.
  79.  
  80. MDS is an ordering code only and is not used as a product name or trademark of Intel Corporation.
  81.  
  82. Intel Corporation and Intel's FASTPATH are not affiliated with Kinetics, a division of Excelan, Inc. or it FASTPATH trademark or products.
  83.  
  84. *  Other brands and names are the property of their respective owners.
  85.  
  86. Additional copies of this document or other Intel literature may be obtained from:
  87.  
  88.         Intel Corporation
  89.         Literature Sales
  90.         P.O. Box 7641
  91.         Mt. Prospect, IL  60056-7641
  92.  
  93.         or call 1-800-879-4683
  94.  
  95.  
  96.  
  97. ╞ INTEL CORPORATION, 1993
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. Table of Contents
  106.  
  107.  
  108. 1.  Introduction     1
  109.  
  110. 2.  Overview of Intel386(tm), Intel486(tm), Pentium(tm) Processors    1
  111. 2.1. The Intel386 Processor    1
  112. 2.1.1.  Instruction Prefetcher    1
  113. 2.1.2.  Instruction Decoder    1
  114. 2.1.3.  Excution Core    1
  115. 2.2. The Intel486 processor    1
  116. 2.2.1.  Integer Pipeline    2
  117. 2.2.2.  On-Chip Cache    2
  118. 2.2.3.  On-Chip Floating-Point Unit    2
  119. 2.3. The Pentium processor    2
  120. 2.3.1.  Integer Pipelines    3
  121. 2.3.2.  Caches    3
  122. 2.3.3.  Instruction Prefetcher    3
  123. 2.3.4.  Branch Target Buffer    3
  124. 2.3.5.  Pipelined Floating-Point Unit    3
  125. 3.  Integer Examples    4
  126. 3.1. Code Sequence 1, Intel486 Processor    5
  127. 3.2. Code Sequence 1, Pentium Processor    6
  128. 3.3. Code Sequence 2, Intel486 Processor    6
  129. 3.4. Code Sequence 2, Pentium Processor    7
  130. 3.5. Code Sequence 3, Intel486 Processor    7
  131. 3.6. Code Sequence 3, Pentium Processor    7
  132. 4.  Code Generation Strategy    9
  133.  
  134. 5.  Blended Code Generation Consideration    10
  135. 5.1.  Choice of Index Versus Base Register    10
  136. 5.2.  Addressing Modes and Register Usage    10
  137. 5.3.  Prefetch Bandwidth    11
  138. 5.4.  Alignment    12
  139. 5.4.1.  Code    12
  140. 5.4.2.  Data    12
  141. 5.4.3.  2-Byte Data    12
  142. 5.4.4.  4-Byte Data    12
  143. 5.4.5.  8-Byte Data    12
  144. 5.5.  Prefixed Opcodes    12
  145. 5.6.  Integer Instruction Scheduling    13
  146. 5.6.1.  Pairing    13
  147. 5.6.2.  Instruction Set Pairability    13
  148.     5.6.2.1.  Unpairable Instructions (NP)    13
  149.     5.6.2.2.  Pairable Instructions Issued to U or V  pipes (UV)....................14
  150.     5.6.2.3.  Pairable Instructions Issued ot U pipe (PU)    14
  151.     5.6.2.4.  Pairable Instructions Issued to V  pipe (PV)    14
  152. 5.6.3.  Unpairability Due to Registers    14
  153. 5.6.4.  Special Pairs    15
  154. 5.6.5.  Restrictions on Pair Execution    16
  155. 5.7.  Integer Instruction Selection    16
  156.  
  157.  
  158.  
  159. 6.  Processor Specific Optimizations    20
  160. 6.1.  Pentium Processor Floating Point    20
  161. 6.1.1.  Floating-Point Example    20
  162. 6.1.2.  FXCH Rules and Regulations    22
  163. 6.1.3.  Memory Operands    23
  164. 6.1.4.  Floating-Point Stalls    23
  165. 7.  Summary    26
  166.  
  167. Appendix A - Instruction Pairing Summary............................................................................A-1
  168.     
  169.  
  170. 1. Introduction
  171.  
  172. The Intel386 Architecture Family represents a series of compatible processors including the
  173. Intel386, Intel486, and the Pentium processors.  The newer members of the family are capable of executing any binaries created for members of previous generations. For example, any existing 8086/8088, 80286, Intel386 (DX or SX), and Intel486 applications will be able to execute on the Pentium processor without any modification or recompilation. However, there are certain code optimization
  174. techniques which will make applications execute faster on a specific member of the family with
  175. little or no impact on the performance of other members. Most of these optimizations deal with
  176. instruction sequence selection and instruction reordering to complement the processor
  177. micro architecture .
  178.  
  179. The intent of this document is to describe the implementation differences of the processor members
  180. and the optimization strategy that gives the best performance for all members of the family.
  181.  
  182. 2. Overview of Intel386, Intel486, and Pentium Processors
  183.  
  184. 2.1 The Intel386 Processor
  185.  
  186. The Intel386 processor is the first implementation of the 32-bit Intel386 architecture. It includes full
  187. 32-bit data paths, rich 32-bit addressing modes and on-chip memory management.
  188.  
  189. 2.1.1. Instruction Prefetcher
  190.  
  191. The instruction prefetcher prefetches the instruction stream from external memory and the prefetched instructions are kept in its four-deep, four-byte-wide prefetch buffers. The instruction decoder operates on the code stream fed to it through the prefetch buffers.
  192.  
  193. 2.1.2. Instruction Decoder
  194.  
  195. The instruction decoder places the decoded information in a three-deep FIFO. It is decoupled from both the prefetcher and the execution core and has separate protocols with each.
  196.  
  197. 2.1.3. Execution Core
  198.  
  199. The core engine executes the incoming instructions one at a time, but for certain cases, it allows overlapping the last execution cycle of the current instruction with the effective address calculation of the next instruction's memory reference.
  200.  
  201. From the compiler writer's point of view, the decoupled prefetch/decode/execution stages and the sequential nature of the core engine has placed few requirements for instruction scheduling.  Avoiding the use of an index in the effective address will save one extra clock. A careful choice of instructions to minimize the execution clock counts is the best optimization approach.
  202.  
  203. 2.2 The Intel486 Processor
  204.  
  205. The Intel486 processor has a full blown integer pipeline delivering a peak throughput of one instruction per clock. It has integrated the first level cache and the floating-point unit on chip, and it has the same on-chip memory management capabilities as the Intel386 processor.
  206.  
  207.  
  208.  
  209. 2.2.1. Integer Pipeline
  210.  
  211. The Intel486 has a five-stage integer pipeline capable of processing one instruction per clock.
  212. The five pipeline stages are:
  213.  
  214. a. Prefetch, (PF) - where instructions are fetched from the cache and placed in one of two 16-byte buffers.
  215.  
  216. b. Decode (D1) - where incoming code stream is being decoded. Prefixed instructions stay in D1 for two clocks.
  217.  
  218. c. Address Generation (D2) - where effective address and linear address are calculated in parallel. The address generation can usually be completed in one cycle except in cases where the indexed addressing mode is used. If the index is used, the instruction stays in D2 for two clocks.
  219.  
  220. d. Execution (E) - where the machine operations are performed. Simple instructions (those with one machine operation) take one cycle to execute giving a maximum throughput of one instruction per clock. The more complex instructions take multiple execution cycles.
  221.  
  222. e. Writeback (WB) - where the needed register update occurs.
  223.  
  224. A taken branch breaks the pipeline stream and causes a two-clock penalty, whereas the pipeline stream is unaffected by a not-taken branch.
  225.  
  226. 2.2.2. On-Chip Cache
  227.  
  228. The on-chip cache is a combined instruction and data cache. It is 8-Kbytes in size, four-way set associative with a 16-byte line size and pseudo-LRU replacement algorithm. All data references have priority access to the cache over instruction prefetch cycles.
  229.  
  230. 2.2.3. On-Chip Floating-Point Unit
  231.  
  232. The on-chip floating-point unit utilizes the integer pipeline for early data access. The bus structure allows 64-bit data to be transferred between the cache and the floating point hardware in one clock. The floating-point design also allows overlapping the floating-point operations with integer operations.
  233.  
  234. The execution core of the Intel486 processor has been architected to maximize the throughput of a class of "frequently used" instructions. Hence, careful selection of an instruction sequence to perform a given task results in faster execution time. Also, code scheduling to avoid pipeline stalls helps to boost application performance. Most of the optimizations targeted to the Intel486 processor do not have negative effects on Intel386 processor.
  235.  
  236. 2.3 The Pentium Processor
  237.  
  238. The Pentium processor is an advanced superscalar processor.  It is built around two general purpose integer pipelines and a pipelined floating-point unit. The Pentium processor can execute two integer instructions simultaneously. A software-transparent dynamic branch-prediction mechanism minimizes pipeline stalls due to branches.
  239.  
  240.  
  241.  
  242.  
  243.  
  244. 2.3.1. Integer Pipelines
  245.  
  246. The Pentium processor has two parallel integer pipelines, the main pipe (U) which is an enhanced Intel486 processor pipe and the secondary pipe (V) which is similar to the main one but has some limitations on the instructions it can execute. The limitations will be described in more
  247. detail in later sections.
  248.  
  249. The Pentium processor can issue two instructions every cycle. During execution, the next two instructions are checked, and if possible, they are issued such that the first one executes in the U pipe, and the second in the V  pipe. (If it is not possible to issue two instructions, then the next instruction is issued to the U pipe and no instruction is issued to the V  pipe.)
  250.  
  251. When instructions execute in the two pipes, their behavior is exactly the same as if they were executed sequentially. When a stall occurs, successive instructions are not allowed to pass the stalled instruction in either pipe. In the Pentium processor's pipelines, the D2 stage can perform a multiway add, so there is not a one-clock index penalty as with the Intel486 pipeline.
  252.  
  253. 2.3.2. Caches
  254.  
  255. The on-chip cache subsystem consists of two (instruction and data) 8-Kbyte, two-way set associative caches with a cache line length of 32 bytes. There is a 64-bit wide external data bus interface. The caches employ a write back mechanism and an LRU replacement algorithm. The data cache consists of eight banks interleaved on four-byte boundaries.  The data cache can be accessed simultaneously from both pipes, as long as the references are to different banks. The minimum delay for a cache miss is 3 clocks.
  256.  
  257. 2.3.3.  Instruction Prefetcher
  258.  
  259. The instruction prefetcher has four buffers, each of which is 32 bytes long. It can fetch an instruction which is split among two cache lines with no penalty. Because the instruction and data caches are separate, instruction prefetches no longer conflict with data references for access to the cache (as in the case of Intel486 processor).
  260.  
  261. 2.3.4.  Branch Target Buffer
  262.  
  263. The Pentium processor employs a dynamic branch prediction scheme with a 256-entry Branch Target Buffer (BTB).  If the prediction is correct, there is no penalty when executing a branch instruction.  There is a 3-cycle penalty if the conditional branch was executed in the U pipe or a 4-cycle penalty if it was executed in the V  pipe. Mispredicted calls and unconditional jump instructions have a 3-clock penalty in either pipe. On the Intel486 processor, taken branches have a two-clock penalty.
  264.  
  265. 2.3.5. Pipelined Floating-Point Unit                             
  266.  
  267. The majority of the frequently used instructions are pipelined so that the pipelines can accept a new pair of operands every cycle. Therefore a good code generator can achieve a throughput of almost 1 instruction per cycle (of course this assumes a program with a modest amount of natural parallelism!). The fxch instruction can be executed in parallel with the commonly used FP instructions, which lets the code generator or programmer treat the floating-point stack as a regular register set without any performance degradation.
  268.  
  269. With the superscalar implementation, it is important to schedule the instruction stream to maximize the usage of the two integer pipelines. Since each of the Pentium processor's integer pipelines is enhanced from the pipeline of the Intel486 processor, the instruction scheduling criteria for the Pentium processor is a superset of the Intel486 processor requirements.
  270.  
  271. 3. Integer Examples
  272.  
  273. With the overview of the Intel386, Intel486 and Pentium processors in the previous section, the examples given in this section further illustrate the execution clock cycles among various instruction sequences.
  274.  
  275. All examples assume a 100% cache hit rate and non-conflicting memory accesses. A 32-bit flat address model is also assumed.
  276.  
  277. There is a cycle count next to each instruction. A cycle count appears without an instruction when there is a pipe stall. These examples also assume that the branch prediction is correct.
  278.  
  279. Going through these examples should give you an intuitive feel for how pairing works on the Pentium processor and additional insight about some of the common delays on both the Intel486 and Pentium processors.
  280.  
  281. C source:
  282.  
  283. static int a[10], b[10];
  284. int i;
  285. for (i=0; i<10; i++) {
  286.     a[i] = a[i] + 1;
  287.     b[i] = b[i] + 1;
  288. }
  289.  
  290. There are various instruction sequences which will produce a correct program. Their individual performance, however, may vary considerably.
  291.  
  292. Here are three examples:
  293.  
  294. Sequence 1    Sequence 2    Sequence 3
  295.  
  296.  xor eax, eax    xor eax, eax    mov eax, -40
  297.  
  298. TopOfLoop:     TopOfLoop:    TopOfLoop:
  299.      mov  edx, eax        inc  dword ptr [eax*4+a]    mov  edx, [eax+40+a]
  300.      shl  edx, 2        inc  dword ptr [eax*4+b]    mov  ecx, [eax+40+b]
  301.      inc  dword ptr [edx+a]        inc  eax        inc  edx
  302.      mov  edx, eax        cmp  eax, 10        inc  ecx
  303.      shl  edx, 2        jl   TopOfLoop        mov  [eax+40+a], edx
  304.      inc  dword ptr [edx+b]        mov  [eax+40+b], ecx
  305.      inc  eax         add  eax, 4
  306.      cmp  eax, 10        jnz  TopOfLoop
  307.      j1   TopOfLoop
  308.  
  309. Code Sequence 1 could benefit from common subexpression elimination. It is not unoptimized code, it is just not thoroughly optimized. Code that is unoptimized would not keep "i" in a register.
  310.  
  311. Code Sequence 2 is the most straight-forward style code.
  312.  
  313. Code Sequence 3 uses a load/store model. It also incorporates some induction variable elimination optimizations with test replacement. The loop counter in eax counts up to zero.  When it becomes zero, the jnz is not taken. This code avoids the compare instruction.
  314.  
  315. The performance of each of these code sequences is examined on both the Intel486 and Pentium 
  316. processors.
  317.  
  318. 3.1.  Code Sequence 1, Intel486 Processor
  319.  
  320. The shl instruction takes two cycles on an Intel486 processor. ALU operations (e.g. add) with
  321. memory results take 3 clocks: 1 to load, 1 to add, and 1 to store.
  322.  
  323.     mov  edx, eax     ; 1
  324.     shl  edx, 2    ; 2   2 clock instruction
  325.       (sh1)    ; 3
  326.     inc  dword ptr [edx+a]    ; 4   3 clocks with memory operand
  327.       (inc)    ; 5     plus 1 clock for edx AGI
  328.       (inc)    ; 6
  329.       (inc)    ; 7
  330.     mov  edx, eax    ; 8
  331.     shl  edx, 2    ; 9   2 clock instruction
  332.       (shl)    ; 10
  333.     inc  dword ptr [edx+b]    ; 11  3 clocks with memory operand
  334.       (inc)    ; 12    plus 1 clock for edx AGI
  335.       (inc)    ; 13
  336.       (inc)    ; 14
  337.     inc  eax    ; 15
  338.     cmp  eax, 10    ; 16
  339.     jl   TopOfLoop     ; 17  2 clocks because jl is prefixed
  340.         ;18
  341.         ; 19  branch taken penalty
  342.         ; 20
  343.     mov  edx, eax    ; 21  next iteration
  344.  
  345. Total: 20 cycles
  346.  
  347. Cycles 4 and 11 had an Address Generation Interlock (AGI) Delay. Register edx was written in cycle 3 and used as a base register in cycle 5. When a register is used in an effective address calculation in the cycle after the register is written, there is a one-clock penalty. This happens because the effective address calculation is performed in the D2 stage of the pipeline.
  348.  
  349. With the assembler used for this code sequence, the jl instruction was a "jump near," not a "jump short." "Jump near" is a 0f prefixed instruction. Prefixed instructions take an extra cycle on the Intel486 processor in the D1 stage.
  350.  
  351. The Intel486 processor does not have any branch prediction mechanism. Whenever jumps are taken,
  352. there is a 2-clock penalty (Cycles 19 and 20).
  353.  
  354.  
  355. 3.2.  Code Sequence 1, Pentium Processor
  356.  
  357. U pipe                V  pipe        
  358.  
  359. mov  edx, eax        ; 1
  360. shl  edx, 2         ; 2
  361. inc  dword ptr [edx+a]        ; 3   3 clocks with mem. op
  362.   (inc)        ; 4     plus 1 for edx AGI
  363.   (inc)        ; 5
  364.   (inc)    mov  edx, eax    ; 6   Pairs with last U cycle
  365. shl  edx, 2        ; 7
  366. inc  dword ptr [edx+b]        ; 8   3 clocks with mem. op
  367.   (inc)        ; 9     plus l for edx AGI
  368.   (inc)        ; 10
  369.   (inc)    inc  eax    ; 11  Pairs with last U cycle
  370. cmp  eax, 10    jl   TopOfLoop    ; 12
  371. mov  edx, eax        ; 13  Next iteration
  372.  
  373. Total :12 cycles
  374.  
  375. Note that the "shift" instruction takes two clocks on the Intel486 processor and only one on the Pentium processor. The Pentium processor has special hardware to avoid the 0f prefix delay on jcc "near" instructions. It also can pair the compare and jump, even though cmp writes a condition flag and jl reads it. The branch prediction hardware, when it predicts the branch to be taken, can execute the target instruction in the cycle following the jump. When a multiple cycle instruction in the U pipe pairs with another instruction, the last memory operation of the U pipe instruction pairs with the first operation of the V  pipe instruction (cycles 6 and 11).
  376.  
  377. 3.3.  Code Sequence 2, Intel486 Processor
  378.  
  379. inc  dword ptr [eax*4+a]     ; 1   3 clocks with memory operand
  380.   (inc)    ; 2     plus 1 for indexing
  381.   (inc)    ; 3
  382.   (inc)    ; 4
  383. inc  dword ptr [eax*4+b]    ; 5   3 clocks with memory operand
  384.   (inc)    ; 6     plus 1 for indexing
  385.   (inc)    ; 7
  386.   (inc)    ; 8
  387. inc  eax    ; 9
  388. cmp  eax, 10    ; 10
  389. jl   TopOfLoop    ; 11  2 clocks because jl is prefixed
  390.     ; 12
  391.     ; 13  Branch taken penalty
  392.     ; 14
  393. inc  dword ptr [eax*4+a]    ; 15  Next iteration
  394.  
  395. Total :14 cycles
  396.  
  397. On the Intel486 processor, whenever an index register is used in an effective address calculation,
  398. there is a one-clock penalty in the D2 stage (Cycles 1 and 5). This does not apply to base
  399. registers.
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407. 3.4.  Code sequence 2, Pentium Processor
  408.  
  409. U pipe                  V  pipe 
  410.  
  411. inc   dword ptr [eax*4+a]     ; 1 3 clocks with mem. op.
  412.   (inc)        ; 2
  413.   (inc)    inc  dword ptr [eax*4+b]    ; 3 1st V pairs with last U
  414.        (inc)    ; 4
  415.       (inc)    ; 5
  416. inc    eax        ; 6
  417. cmp    eax, 10    jl  TopOfLoop    ; 7
  418. inc    dword ptr [eax*4+a]    ; 8 Next iteration
  419.  
  420. Total: 7 cycles
  421.  
  422. The inc eax instruction at cycle 6 did not pair with the cmp instruction because of a register dependence. Other than in a few special cases (such as cmp-jmp), a register cannot be accessed until the cycle after it is written.
  423.  
  424. 3.5.  Code Sequence 3, Intel486 Processor
  425.  
  426.     mov  edx, [eax+40+a]    ; 1
  427.         ; 2   Fill prefetch buffer
  428.     mov  ecx, [eax+40+b]    ; 3
  429.     inc  edx    ; 4
  430.     inc  ecx    ; 5
  431.     mov  [eax+40+a], edx    ; 6
  432.     mov  [eax+40+b], ecx     ; 7
  433.     add  eax, 4    ; 8
  434.     jnz  TopOfLoop    ; 9   Prefix on jnz
  435.         ; 10
  436.         ; 11  Branch penalty
  437.             ; 12
  438.     mov  edx, [eax+40+a]    ; 13  Next iteration
  439.  
  440. Total : 12 cycles
  441.  
  442. The delay at clock 2 is caused by a miss in the Intel486 processor's prefetch buffer. The previous two examples had a similar penalty, but it was hidden by the 2-clocks used for the shl instruction in code sequence 1, and by the index penalty in code sequence 2.
  443.  
  444. 3.6.  Code Sequence 3, Pentium Processor
  445.  
  446. U pipe       V  pipe
  447.  
  448. mov  edx, [eax+40+a]    mov  ecx, [eax+40+b]    ; 1
  449. inc  edx    inc  ecx    ; 2
  450. mov  [eax+40+a], edx    mov  [eax+40+b], ecx    ; 3
  451. add  eax, 4    jnz  TopOfLoop    ; 4
  452. mov  edx, [eax+40+a]    mov  ecx, [eax+40+b]    ; 5 AGI on eax with
  453.   (mov)                           (mov)    ; 6 next iteration
  454.  
  455. Total: 5 cycles
  456.  
  457. The prefetch buffer delay on the Intel486 processor is no longer relevant. The Pentium processor has more prefetch buffers and different alignment capabilities. In the example above, the loop control is determined by the add eax, 4 instruction setting the zero condition code as it counts up to zero.
  458.  
  459. There is an AGI on eax because the add in cycle 4 writes to eax and both mov' s in cycle 5 reference it, even though there is a branch in between. On the Intel486 processor, AGl's only happen between adjacent instructions. On the Pentium processor, there can be two instructions in between and still be an AGI; for example, between a U pipe add in cycle n and a V  pipe mov that uses the result of the add as a base in cycle n+1. The general rule is than an AGI will occur when any instruction in cycle n writes to a register that is used in an effective address calculation in any instruction in cycle n+1. This is because the effective address calculation is performed in D2.
  460.  
  461. In a compiler's intermediate representation of the program before instruction scheduling (reordering), one might expect the order for sequence 3 to be:
  462.  
  463. load [a+eax+40]            load [b+eax+40]
  464.        |                             |
  465.        |                             |
  466.        add 1                      add 1
  467.         |                             |
  468.         |                             |
  469.      store [a+eax+40]      store [b+eax+40]
  470.                 |                 |            
  471.                 |                 |            
  472.                    add  eax, 1
  473.                          |
  474.                          |
  475.                      cmp  10
  476.                          |
  477.                          |
  478.                        jump
  479.  
  480. Reordering this intermediate code to obtain the assembly code shown earlier involves moving the load from "b" in front of the store into "a." Instruction reordering requires knowing that memory operands are independent. In this case, it can be easily proven that elements of "a" do not overlap in memory with elements of "b."
  481.  
  482. Comments              
  483.  
  484. Using a load/store paradigm works well on the Pentium processor because it exposes more opportunities for pairing instructions when the instructions are scheduled.  It does not however, increase the number of clocks, even without scheduling, though this ignores possible secondary effects such as larger code size.   This can lead to instruction cache misses.  Another secondary effect is the use of more registers, which are a limited resource on these processors. Compiler writers may want to pay more attention to register allocation.
  485.  
  486. In this document, we will refer to this as "load/store" style code generation.
  487.  
  488.  
  489. 4. Code Generation Strategy
  490.  
  491. Even though each member of the Intel386 processor family has a different micro architecture due to
  492. technology versus implementation tradeoffs, the differences induced few conflicts in the overall code optimization strategy. In fact, there is a set of "blended" optimizations that will create an optimal binary across the entire family. The "blended" optimizations include:
  493.  
  494. 1. Optimizations that benefit all members.
  495.  
  496. 2. Optimizations that benefit one or more members but do not hurt the remaining members.
  497.  
  498. 3. Optimizations that benefit one or more members a lot but only hurt the remaining members
  499.     a little.
  500.  
  501. For those optimizations that benefit only certain members but cause noticeable degradation to others, it is recommended that they be implemented under switches and left to the user to decide whether maximizing the performance of a specific processor is desirable.
  502.  
  503.  
  504. 5. Blended Code Generation Consideration
  505.  
  506. 5.1 Choice of Index Versus Base Register
  507.  
  508. The Intel386 and the Intel486 processors need an additional clock cycle to generate an effective address when an index register is used. Therefore, if only one indexing component is used (i.e., not both a base register and an index register) and scaling is not necessary, then it is faster to use the register as a base rather than an index. For example:
  509.  
  510. mov  eax, [esi]  ; use esi as base
  511. mov  eax, [esi*] ; use esi as index, 1 clock penalty
  512.  
  513. It takes the Pentium processor one clock to calculate the effective address even when an index register is used.  Hence, Pentium processor is neutral to the choice of index versus base register.
  514.  
  515. 5.2. Addressing Modes and Register Usage
  516.  
  517. 1. For the Intel486 processor, when a register is used as the base component, an additional clock cycle is used if that register is the destination of the immediately preceding instruction (assuming all instructions are already in the prefetch queue). For example:
  518.  
  519. add  esi, eax    ; esi is destination register
  520. mov  eax, [esi]  ; esi is base, 1 clock penalty
  521.  
  522. Since the Pentium processor has two integer pipelines and each pipeline has a similar organization on the Intel486 processor, a register used as the base or index component of an effective address calculation (in either pipe) causes an additional clock cycle if that register is the destination of either instruction from the immediately preceding cycle (Address Generation Interlock, (AGI)). To avoid the AGI, the instructions should be separated by at least one cycle by placing other instructions between them.
  523.  
  524. 2. Note that some instructions have implicit reads/writes to registers. Instructions that generate addresses implicitly through esp (push,pop/ret/call) also suffer from the AGI penalty.
  525.  
  526. Examples:
  527.  
  528. sub  esp, 24
  529.         ;  1 cycle stall
  530. push ebx
  531.  
  532.  
  533. mov  esp, ebp
  534.         ;  1 cycle stall
  535. pop  ebp
  536.  
  537. Push and pop also implicitly write to esp. This, however, does not cause an AGI when the next instruction addresses through esp.
  538.  
  539. Example:
  540.  
  541. push edi          ; no stall
  542. mov  ebx, [esp]
  543.  
  544.  
  545.  
  546. 3. On the Intel486 processor there is a 1-clock penalty for decoding an instruction with either an
  547. index or an immediate-displacement combination. On the Pentium processor, the immediate-displacement combination is not pairable. When it is necessary to use constants, it would still be more efficient to use immediate data instead of loading the constant into a register first.  However, if the same immediate data is used more than once, it would be faster to load the constant in a register and then use the register multiple times.
  548.  
  549. mov  result, 555     ; 555 is immediate, result is displacement
  550. mov  dword ptr [esp+4], 1    ; 1  is immediate,      4 is displacement
  551.  
  552. 4. The Intel486 processor has a 1-clock penalty when using a register immediately after its sub-
  553. register was written.  The Pentium processor is neutral in this respect.
  554.  
  555. Example (Pentium Processor):
  556.  
  557. mov  al,       0     ; 1
  558. mov  [ebp], eax     ; 2 - No delay on the Pentium processor
  559.  
  560. Example (Intel486 processor):
  561.  
  562. mov  al,       0     ; 1
  563.     ; 2
  564. mov  [ebp], eax    ; 3
  565.  
  566. 5.3 Prefetch Bandwidth
  567.  
  568. The Intel486 processor prefetch unit will access the on-chip cache to fill the prefetch queue whenever the cache is idle and there is enough room in the queue for another cache line (16 bytes). If the prefetch queue becomes empty, it can take up to three additional clocks to start the next instruction. The prefetch queue is 32 bytes in size (2 cache lines).
  569.  
  570. Because data accesses always have priority over prefetch requests, keeping the cache busy with data accesses can lock out the prefetch unit. As a result, optimized code should avoid four consecutive memory instructions.
  571.  
  572. It is important to arrange instructions so that the memory bus is not used continuously by a series of memory-reference instructions. The instructions should be rearranged so that there is a non-memory referencing instruction (such as a register instruction) at least two clocks before the prefetch queue becomes exhausted. This will allow the prefetch unit to transfer a cache line into the queue.
  573.  
  574. Such arrangement of the instructions will not affect the performance of the Intel386 and Pentium
  575. processors.
  576.  
  577. In general, it is difficult for a compiler to model the Intel486 prefetch buffer behavior. A sequence of four consecutive memory instructions without stalls (i.e., index penalty) will probably stall because of the prefetch buffers being exhausted.
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586. 5.4 Alignment
  587.  
  588. 5.4.1 Code                   
  589.        
  590. The Intel486 processor has a cache line size of 16 bytes and the Pentium processor has a cache line size of 32 bytes. Since the Intel486 processor has only two prefetch buffers (16 bytes each), code alignment has a direct impact on Intel486 processor performance as a result of the prefetch buffer efficiency. Code alignment has little effect on the Pentium processor performance because of its ability to prefetch across a cache line boundary with no penalty.  The Intel386 processor with no on-chip cache and a decoupled prefetch unit is not sensitive to code alignment. For optimal performance across the family, it is recommended that labels be aligned to the next 0MOD16 when it is less than 8 bytes away from that boundary.
  591.  
  592. 5.4.2. Data
  593.  
  594. A misaligned access in the data cache costs at least an extra 3 cycles on both the Intel486 and Pentium processor.
  595.  
  596. 5.4.3.  2-byte Data: A 2-byte object should be fully contained within an aligned 4-byte word (i.e., its binary address should be xxxx00, xxxx01, xxxx10, but not xxxx11).
  597.  
  598. 5.4.4.  4-byte Data: The alignment of 4-byte object should be on a 4-byte boundary.
  599.  
  600. 5.4.5.  8-byte Data:  An 8-byte datum (64-bit, e.g., double-precision reals) should be aligned on an 8-byte boundary.
  601.  
  602. 5.5 Prefixed Opcodes
  603.  
  604. On the Intel386 processor and the Intel486 processor, all prefix opcodes require an additional clock to decode. On the Pentium processor, an instruction with a prefix is pairable in the U pipe (PU) if the instruction (without the prefix) is pairable in both pipes (UV) or in the U pipe (PU). This is a special case of pairing. The prefixes are issued to the U pipe and get decoded in one cycle for each prefix and then the instruction is issued to the U pipe and may be paired.
  605.  
  606. All these prefixes: lock, segment override, address size, second opcode map (Of), and operand size belong to this group. Note that this includes all the 16 bit instructions when executing in 32-bit mode because an operand size prefix is required (e.g., mov word ptr [..], add word ptr [..], ...)
  607.  
  608. The near jcc prefix behaves differently; it does not take an extra cycle to decode and belongs to PV group.  Other 0f opcodes behave as normal prefixed instructions. For optimized code, prefixed opcodes should be avoided.
  609.  
  610. When prefixed opcodes have to be used, there are two cases in which overlap can be achieved between the extra clock it takes to decode a prefix and a cycle used by the previous instruction executing in the same pipe:
  611.  
  612. 1. The one-cycle penalty from using the result register of a previous instruction as a base or index (AGI).
  613.  
  614. 2. The last cycle of a preceding multi-cycle instruction.
  615.  
  616.  
  617.  
  618.  
  619.  
  620. 5.6 Integer Instruction Scheduling
  621.  
  622. Instruction scheduling is the process of reordering the instructions in a program to avoid stalls
  623. and delays while maintaining the semantics of the generated code.
  624.  
  625. Scheduling of integer instructions has two purposes:
  626.  
  627. 1.  Eliminate stalls in the Intel486 pipeline and each pipe of the Pentium processor.
  628.  
  629. There are some conditions where pipe stalls are encountered. The general guideline is to find instructions that can be inserted between the instructions that cause a stall. Since most of the commonly used integer instructions take only one clock, there is not much need to hide latencies. The most common delays which can be avoided through scheduling are AGI 's.
  630.  
  631. 2.  Create pairs for maximum throughput from the Pentium processor's dual pipe architecture:
  632.  
  633. The Pentium processor can issue two instructions for execution simultaneously. This is called pairing. There are limitations on which two instructions can be paired and some pairs, even when issued, will not execute in parallel. Pairing details are described in following sections.  More information about instruction pairability can be found in Appendix A.
  634.  
  635. Reordering instructions should be done in order to increase the possibility of issuing two instructions simultaneously.  Dependent instructions should be separated by at least one other instruction. Scheduling for the Pentium processor's dual pipe is overkill for the Intel486 processor but has otherwise little effect on its performance.
  636.  
  637. The following subsections are Pentium processor specific optimizations. These optimizations do not adversely impact the Intel386 and Intel486 processors.
  638.  
  639. 5.6.1. Pairing
  640.  
  641. Pairing cannot be performed when the following conditions occur:
  642.  
  643. 1. The next two instructions are not pairable instructions (See Appendix A for pairing characteristics of individual instructions.  In general, most simple ALU instructions are pairable.
  644.  
  645. 2. The next two instructions have some type of register contention (implicit or explicit). There are some special exceptions to this rule where register contention can occur with pairing. These are described later.
  646.  
  647. 3. The instructions are not both in the instruction cache.  An exception to this which permits pairing is if the first instruction is a one byte instruction.
  648.  
  649. 5.6.2.  Instruction Set Pairability
  650.  
  651. 5.6.2.1  Unpairable instructions (NP)
  652.  
  653. 1. shift/rotate with the shift count in cl
  654.  
  655. 2. Long-Arithmetic instructions, for example,  mul, div
  656.  
  657. 3. Extended instructions, for example, ret, enter, pusha, movs, rep stos, loopnz
  658.  
  659. 4. Some Floating-Point Instructions, for example, fscale, fldcw, fst
  660.  
  661. 5. Inter-segment instructions, for example, push sreg, call far
  662.  
  663. 5.6.2.2   Pairable instructions issued to U or V  pipes (UV)
  664.  
  665. 1. Most 8/32-bit ALU operations, for example, add, inc, xor,
  666.  
  667. 2. All 8/32-bit compare instructions, for example cmp, test
  668.  
  669. 3. All 8/32-bit stack operations using registers, for example, push reg, pop reg
  670.  
  671.  5.6.2.3  Pairable instructions issued to U pipe (PU)
  672.  
  673. These instructions must be issued to the U pipe and can pair with a suitable instruction in the V
  674. Pipe. These instructions never execute in the V pipe.
  675.  
  676. 1. Carry and borrow instructions, for example, adc, sbb
  677.  
  678. 2. Prefixed instructions (see next section)
  679.  
  680. 3. Shift with immediate
  681.  
  682. 4. Some Floating-Point Operations, for example, fadd, fmul, fld
  683.  
  684. 5.6.2.4  Pairable instructions issued to V  pipe (PV)
  685.  
  686. These instructions can execute in either the U pipe or the V pipe, but they are only paired when they are in the V  pipe. Since these instructions change the instruction pointer (eip), they cannot pair in the U pipe because the next instruction may not be adjacent. Even when a branch in the U pipe is predicted "not taken", it will not pair with the following instruction.
  687.  
  688. 1. Simple control transfer instructions, for example - call near, jmp near, jcc. This includes both the jcc short and the jcc near (which has a 0f prefix) versions of the conditional jump instructions.
  689.  
  690. 2. fxch
  691.  
  692. 5.6.3.  Unpairability Due to Registers
  693.  
  694. The pairability of an instruction is also affected by its operands. The following are the combinations that are not pairable due to register contention. Exceptions to these rules are given in the next section.
  695.  
  696. 1. The first instruction writes to a register that the second one reads from (flow-dependence).
  697.  
  698. Example:
  699.  
  700.      mov  eax, 8
  701.      mov  [ebp], eax
  702.  
  703.  
  704. 2. Both instructions write to the same register (output-dependence).
  705.  
  706. Example:
  707.  
  708.      mov  eax, 8
  709.      mov  eax, [ebp]
  710.  
  711. This limitation does not apply to a pair of instructions which write to the eflags register (e.g. two ALU operations that change the condition codes). The condition code after the paired instructions execute will have the condition from the V pipe instruction.
  712.  
  713. Note that a pair of instructions in which the first reads a register and the second writes to it (anti- dependence) is pairable.
  714.  
  715. Example:
  716.  
  717.      mov  eax, ebx       mov  ebx, [ebp]
  718.  
  719. For purposes of determining register contention, a reference to a byte or word register is treated
  720. as a reference to the containing 32-bit register. Hence,
  721.  
  722.      mov  al, 1
  723.      mov  ah, 0
  724.  
  725. do not pair due to apparent output dependencies on eax.
  726.  
  727. 5.6.4 Special Pairs
  728.  
  729. There are some instructions that can be paired although the general rule prohibits this. These special pairs overcome register dependencies. Most of these exceptions involve implicit reads/writes to the esp register or implicit writes to the condition codes:
  730.  
  731. Stack Pointer:
  732.  
  733. 1. push reg/imm; push reg/imm
  734.  
  735. 2. push reg/imm; call
  736.  
  737. 3. pop reg     ; pop reg
  738.  
  739. Condition Codes:
  740.  
  741. 1. cmp         ; jcc
  742.  
  743. 2. add         ; jne
  744.  
  745. Note that the special pairs that consist of push/pop instructions may have only immediate or register operands.
  746.  
  747.  
  748. 5.6.5 Restrictions on Pair Execution
  749.  
  750. There are some pairs that may be issued simultaneously but will not execute in parallel:
  751.  
  752. 1. If both instructions access the same data-cache memory bank then the second request (V  pipe) must wait for the first request to complete. A bank conflict occurs when bits 2-4 are the same in the two physical addresses. This is because the cache is organized as 8 banks of 32-bit wide data entries. A bank conflict incurs a one clock penalty on the V pipe instruction .
  753.  
  754. 2. Inter-pipe concurrency in execution preserves memory-access ordering. A multi-cycle instruction in the U pipe will execute alone until its last memory access.
  755.  
  756.     add  eax, meml    add  ebx, mem2     ; 1
  757.       (add)       (add)    ; 2  2-cycle
  758.  
  759. The instructions above add the contents of the register and the value at the memory location, then put the result in the register. An add with a memory operand takes two clocks to execute. The first clock loads the value from cache, and the second clock performs the addition. Since there is only one memory access in the U pipe instruction, the add in the V  pipe can start in the same cycle.
  760.  
  761.     add  meml, eax         ; 1
  762.         (add)         ; 2
  763.          (add)    add  mem2, ebx    ; 3
  764.            (add)    ; 4
  765.            (add)    ; 5
  766.  
  767. The above instructions add the contents of the register to the memory location and store the result at the memory location. An add with a memory result takes 3 clocks to execute.  The first clock loads the value, the second performs the addition, and the third stores the result. When paired, the last cycle of the U pipe instruction overlaps with the first cycle of the V pipe instruction execution.
  768.  
  769. No other instructions may begin execution until the instructions already executing have
  770. completed.
  771.  
  772. To expose the opportunities for scheduling and pairing, it is better to issue a sequence of simple instructions rather than a complex instruction that takes the same number of cycles. The simple instruction sequence can take advantage of more issue slots.  Compiler writers/programmers can also choose to reconstruct the complex form if the pairing opportunity does not materialize. The load/store style code generation requires more registers and increases code size. This impacts Intel486 processor performance, although only as a second order effect. To compensate for the extra registers needed, extra effort should be put into the register allocator and instruction scheduler so that extra registers are only used when parallelism increases.
  773.  
  774. 5.7 Integer Instruction Selection
  775.  
  776. The following highlights some instruction sequences to avoid and some sequences to use when generating optimal assembly code.
  777.  
  778. The lea instruction can be advantageous:
  779.  
  780. a. Lea may be used sometimes as a three/four operand addition instruction
  781.             e.g.,  lea  ecx, [eax+ebx+4+a]
  782.  
  783. b. In many cases an lea instruction or a sequence of lea, add, sub and the shift instructions may be used to replace constant multiply instructions.
  784.  
  785. c. This can also be used to avoid copying a register when both operands to an add are still needed  after the add, since lea need not overwrite its operands.
  786.  
  787. The disadvantage of the lea instruction is that it increases the possibility of an AGI stall with previous instructions. Lea is useful for shifts of 2,4,8 because the shift instructions take 2 clocks on Intel486 processor whereas lea only takes one.  On the Pentium processor, lea can execute in either U or V pipes, but the shift instructions can only execute in the U pipe. 
  788.  
  789. Complex instructions
  790.  
  791. Avoid using complex instructions (for example, enter, leave, loop).  Use sequences of simple
  792. instructions instead.
  793.  
  794. Zero-Extension of Short
  795.  
  796. The movzx instruction has a prefix and takes 3 cycles to execute, totaling 4 cycles. As with the Intel486 processor, it is recommended the following sequence be used instead:
  797.  
  798. xor  eax, eax
  799. mov  al, mem
  800.  
  801. If this occurs within a loop, it may be possible to pull the xor out of the loop if the only assignment to eax is the mov al, mem. This has greater importance for the Pentium processor since the movzx is not pairable and the new sequence may be paired with adjacent instructions.
  802.  
  803. Push mem
  804.  
  805. The push mem instruction takes four cycles for the Intel486 processor. It is recommended to use the following sequence because it takes only two cycles for the Intel486 processor and increases pairing opportunity for the Pentium processor.
  806.  
  807. mov  mem, reg
  808. push reg
  809.  
  810. Short Opcodes
  811.  
  812. Use one-byte long instructions as much as possible. This will reduce code size and help increase instruction density in the instruction cache. The most common example is using inc and dec rather than adding or subtracting the constant 1 with add or sub.
  813.  
  814. 8/16 bit operands
  815.  
  816. With 8-bit operands, try to use the byte opcodes, rather than using 32-bit operations on sign and zero extended bytes. Prefixes for operand size override apply to 16-bit operands, not to 8-bit operands.
  817.  
  818. Sign Extension is usually quite expensive. Often, the semantics can be maintained by zero extending 16-bit operands. Specifically, the C code in the following example does not need sign extension nor does it need prefixes for operand size overrides.
  819.  
  820. static short int a, b;
  821. if (a==b) {
  822.    . . .
  823. }
  824.  
  825. Code for comparing these 16-bit operands might be:
  826.  
  827.                           U pipe                V  pipe        
  828.  
  829.         xor  eax, eax     xor  ebx, ebx          ; 1
  830.         movw    ax, [a]                    ; 2 (prefix) + 1
  831.         movw    bx, [b]                    ; 4 (prefix) +1                              cmp  eax, ebx                            ; 6
  832.  
  833. The straight-forward method may be slower:
  834.  
  835. movsw     eax, a    ; 1  1 prefix + 3
  836. movsw     ebx, b    ; 5
  837. cmp        ebx, eax     ; 9
  838.  
  839. Of course, this can only be done under certain circumstances, but the circumstances tend to be quite common. This would not work if the compare was for greater than, less than, greater than or equal, and so on, or if the values in eax or ebx were to be used in another operation where sign extension was required.
  840.  
  841. Compares
  842.  
  843. Use test when comparing a value in a register with 0. Test essentially "ands" the operands together without writing to a destination register. If you "and" a value with itself and the result sets the zero condition flag, the value was zero. Test is preferred over and because the and writes the result register which may subsequently cause an AGI.  Test is better than cmp  .., 0 because the instruction size is smaller.
  844.  
  845. Use test when comparing the result of a Boolean "and" with an immediate constant for
  846. equality or inequality if the register is eax. (if (avar & 8) { }).
  847.  
  848. Test is a one-cycle pairable instruction when the form is eax, imm or reg, reg. Other
  849. forms of test take two cycles and do not pair.
  850.  
  851. Address Calculations
  852.  
  853. Pull address calculations into load and store instructions. Internally, memory reference instructions can have 4 operands: a relocatable load-time constant, an immediate constant, a base register, and a scaled index register. (In the segmented model, a segment register may constitute an additional operand in the linear address calculation.) In many cases, several integer instructions can be eliminated by fully using the operands of memory references.
  854.  
  855. When there is a choice to use either a base or index register, always choose the base because there is a 1-clock penalty on the Intel486 processor for using an index.
  856.  
  857. Clearing a Register
  858.  
  859. The preferred sequence to move zero to a register is xor reg, reg. This saves code space but sets the condition codes. In contexts where the condition codes must be preserved, use mov reg, 0.
  860.  
  861. Integer Divide
  862.  
  863. Typically, an integer divide is preceded by a cdq instruction (Divide instructions use edx: eax as the dividend and cdq sets up edx). It is better to copy eax into edx, then right shift edx 31 places to sign extend. The copy/shift takes the same number of clocks as cdq on both the Pentium and Intel486 processors, but the copy/shift  scheme allows two other instructions to execute at the same time on the Pentium processor.  If you know the value is positive, use xor edx, edx.
  864.  
  865. Prolog Sequences
  866.  
  867. Be careful to avoid AGl's in the prolog due to register esp. Since push can pair with other push instructions, saving callee-saved registers on entry to functions should use these instructions. If possible, load parameters before decrementing esp.
  868.  
  869. In  routines that do not call other routines (leaf routines), use esp as the base register to free up ebp. If you are not using the 32-bit flat model,  remember that ebp cannot be used as a general purpose base register because it references the stack segment.
  870.  
  871. Avoid Compares with Immediate Zero
  872.  
  873. Often when a value is compared with zero, the operation producing the value sets condition codes which can be tested directly by a jcc instruction. The most notable exceptions are mov and lea. In these cases, use test.
  874.  
  875. Epilog Sequence
  876.  
  877. If only 4 bytes were allocated in the stack frame for the current function, instead of incrementing the stack pointer by 4, use pop instructions. This avoids AGls and helps both Intel486 and Pentium processor.  For Pentium processor use 2 pops for eight bytes.
  878.  
  879. Integer Multiply by Constant 
  880.  
  881. The integer multiply by an immediate can usually be replaced by a faster series of shifts, adds, subs, and leas.
  882.  
  883. a. Binary Method
  884.  
  885. In general, if there are 8 or fewer bits set in the binary representation of the constant, it is better not to do the integer multiply. On an Intel486 processor, the break even point is lower: it is profitable if 6 bits or less are in the constant. Basically, shift and add for each bit set.
  886.  
  887. b. Factorization Method
  888.  
  889. This is done by factoring the constant by powers of two plus or minus one, and the constant plus or minus one by powers of two. If the number can be factored by powers of two, then the multiplication can be performed by a series of shifts. If powers of two plus or minus one are included, a shift of the previous
  890. result and an add or subtract of the previous result can be generated.  If the given number plus or minus one can be factored by a power of two, a shift of the previous result and an add or subtract of the original operand can be generated.   An iterative for checking powers of two from 31 to 1 can be done.  The shift amount needed and an ordinal to specify an add or subtract is saved for each factor. This information can be used in reverse order to generate the needed instructions.
  891.  
  892. For example:
  893.  
  894. imul  eax, 217      ; 10 clocks, no pairing
  895.  
  896. In checking powers of two in decreasing order  it is found that 217 will divide by 31.
  897.       217/31 = 7.       31 = (2^^5)-1
  898.  
  899. save shift = 5 and ordinal = sub_previous_result
  900.  
  901. After a check of 217/31 or 7, it is found that 7+1 is divisible by 8.
  902.  
  903. save shift = 3 and ordinal = sub_operand
  904.  
  905. After factoring, the instructions can be generated in reverse.
  906.  
  907.               mov  ecx, eax       ; 1
  908.        shl  eax, 3         ; 2           
  909.        sub  eax, ecx       ; 3
  910.        mov  ecx, eax       ; 4
  911.        shl  eax, 5         ; 5
  912.        sub  eax, ecx       ; 6                    
  913.  
  914. This code sequence allows scheduling of other instructions in the Pentium processor's V  pipe.
  915.  
  916. 6. Processor Specific Optimizations
  917.  
  918. 6.1 Pentium Processor Floating-Point Optimizations
  919.  
  920. The Pentium processor is the first generation of the Intel386 family that implements a pipelined floating-point unit.  However, in order to achieve maximum throughput from the Pentium processor floating-point unit, specific optimizations must be done.
  921.  
  922. 6.1.1 Floating-Point Example
  923.  
  924. FORTRAN source:
  925.  
  926.     subroutine da(x,y,z,n)
  927.     dimension x(n),y(n)
  928.  
  929.     do 10 i=l,n
  930. 10        x(i) = x(i) + y(i) * z
  931.  
  932.     return
  933.     end
  934.  
  935.  
  936. Assembly code:                            
  937.  
  938.                                       Pentium/Intel486 processor
  939.     TopOfLoop:
  940.         fld   dword ptr [esp+8]         ; 1    /    1
  941.         fmul  dword ptr [ebx+eax*4]     ; 2    /    5
  942.         fadd  dword ptr [ecx+eax*4]     ; 5    /   16
  943.         fstp  dword ptr [ecx+eax*4]        ; 9    /   26
  944.         inc   eax                         ; 11   /   33
  945.         cmp   eax, ebp                    ; 12   /   34
  946.         jle      TopOfLoop                   ; 12   /   36+2 for branch
  947.  
  948. Total :12 cycles per iteration
  949.  
  950. On the Intel486 processor, the time it takes to add and multiply varies depending on the values. In this example, 11 was used for multiply and 10 for add. The load takes 3 clocks; the store requires 7 clocks. The extra cycle before the fmul is an index penalty for the fmul. The fadd and fstp do not show an index penalty because the penalty overlapped with the execution of the previous floating-point instruction. These overlaps do not occur with fld or fxch.
  951.  
  952. On the Pentium processor, the results of fadd and fmul can be used three cycles after they start, except when the use is fst. When an fst instruction uses the result of another floating-point operation, an extra cycle is needed. The fst instruction executes for two cycles and nothing can execute in parallel.
  953.  
  954. There is an enormous improvement due to decreasing the clock counts for the common floating-point instructions; however, this example does not overlap any floating-point instructions. A further improvement can be achieved by overlapping the execution of the floating-point instructions as explained in the next section.
  955.  
  956. To expose more parallelism, loop unrolling can be used if the iterations are independent.
  957. Following is the assembly code after unrolling:
  958.  
  959.                                      Pentium processor     Intel486 CPU
  960.    TopOfLoop:
  961.         fld   dword ptr [esp+8]     ;  1                   1
  962.         fmul  dword ptr [ebx+eax*4]    ;  2                   5
  963.         fadd  dword ptr [ecx+eax*4]    ;  5                  16
  964.         fstp  dword ptr [ecx+eax*4]     ;  9                  26
  965.         fld   dword ptr [esp+8]    ;  11                 33
  966.         fmul  dword ptr [ebx+eax*4+4]    ;  12                 37
  967.         fadd  dword ptr [ecx+eax*4+4]    ;  15                 48
  968.         fstp  dword ptr [ecx+eax*4+4]    ;  19                 58
  969.         fld   dword ptr [esp+8]    ;  21                 65
  970.         fmul  dword ptr [ebx+eax*4+8]    ;  22                 69
  971.         fadd  dword ptr [ecx+eax*4+8]    ;  25                 80
  972.         fstp  dword ptr [ecx+eax*4+8]    ;  29                 90
  973.         add   eax, 3    ;  31                 97
  974.         cmp   eax, ebp    ;  32                 98
  975.         jle   TopOfLoop    ;  32            100+2 (br taken)
  976.  
  977. Total: 32 cycles (10.7/ iteration)
  978.  
  979. The clock count improvements gained through loop unrolling was due to eliminating some of the loop control overhead.  To get more improvement, we need to get the floating-point operations overlapped in order to hide their latencies.
  980.  
  981. Most floating-point operations require that one operand and the result use the top of stack. This makes each instruction dependent on the previous instruction and inhibits overlapping the instructions .
  982.  
  983. One obvious way to get around this is to change the architecture and have floating-point registers, rather than a stack. Unfortunately, upward and downward compatibility would be lost.   Instead, the fxch instruction was made "fast". This provides us another way to avoid the top of stack dependencies.  The fxch instructions can be paired with the common floating-point operations, so there is no penalty on the Pentium processor.  On the Intel486 processor, each fxch takes 4 clocks.
  984.  
  985. To take advantage of the exposed parallelism from loop unrolling, the instructions should be scheduled.
  986.  
  987.  
  988. Assembly code after unrolling and scheduling:
  989.  
  990.                                                         After Instruction
  991.                                     Intel486  Pentium   ST(O)     ST(l)    ST(2)
  992.                                        CPU      CPU     --------  -------- -----
  993. TopOfLoop: 
  994.     fld       dword ptr [esp+8]          1       1      z
  995.     fmul      dword ptr [ebx+eax*4]      5       2      y0*z
  996.     fld       dword ptr [esp+8]         16       3      z         y0*z
  997.     fmul      dword ptr [ebx+eax*4+4]   20       4      yl*z      y0*z
  998.     fxch      st(l)                     31       4      y0*z      yl*z
  999.     fadd      dword ptr [ecx+eax*4]     36       5      x0+y0*z   yl*z
  1000.     fld       dword ptr [esp+8]         46       6      z         x0+y0*z   yl*z
  1001.     fmul      dword ptr [ebx+eax*4+8]   50       7      y2*z      x0+y0*z   yl*z
  1002.     fxch      st(2)                     61       7      yl*z      x0+y0*z   y2*z
  1003.     fadd      dword ptr [ecx+eax*4+4]   66       8      xl+yl*z   x0+y0*z   y2*z
  1004.     fxch      st(l)                     76       8      x0+y0*z   xl+yl*z   y2*z
  1005.     fstp      dword ptr [ecx+eax*4]     81       9      xl+yl*z   y2*z
  1006.     fxch      st(l)                     88      11      y2*z      xl+yl*z
  1007.     fadd      dword ptr [ecx+eax*4+8]   93      12      x2+y2*z   xl+yl*z
  1008.     fxch      st(l)                    103      12      xl+yl*z   x2+y2*z
  1009.     fstp      dword ptr [ecx+eax*4+4]  108      13      x2+y2*z
  1010.     fstp      dword ptr [ecx+eax*4+8]  116      16
  1011.     add       eax, 3                   123      18
  1012.     cmp       eax, ebp                 124      19
  1013.     jle       TopOfLoop                126+2    19
  1014.  
  1015.                                            |
  1016.  
  1017.                                        (jle taken)
  1018.  
  1019. Total :1 9 cycles (6.3/iteration)
  1020.  
  1021. On the Intel486 processor, the index penalty and the added cost of fxch are apparent. The index penalty does not overlap with the fxch instruction.
  1022.  
  1023. On the Pentium processor, the fxch instructions pair with preceding fadd and fmul instructions and execute in parallel with them (cycles 7,8,12). The fxch instructions move an operand into position for the next floating point instruction. There is a cycle lost at clock 15 due to the store waiting 3 clocks after the instruction defining its operand.  The fxch instruction does not pair with fst and takes one clock as a separate instruction (cycles 9-11)
  1024.  
  1025. 6.1.2 FXCH Rules and Regulations
  1026.  
  1027. The fxch instruction can be executed for "free" when all of the following conditions occur:
  1028.  
  1029.  An FP instruction follows the fxch instruction.
  1030.  
  1031. An FP instruction belonging to the following list immediately precedes the fxch instruction: fadd, fsub, fmul, fld, fcom, fucom, fchs, ftst, fabs, fdiv.
  1032.  
  1033. This fxch instruction has already been executed. This is because the instruction boundaries in the cache are marked the first time the instruction is executed, so pairing only happens the second time this instruction is executed from the cache.
  1034.  
  1035. This means that this instruction is almost "free" and can be used to access elements in the deeper levels of the FP stack instead of storing them and then loading them again.
  1036.  
  1037.  
  1038. 6.1.3 Memory Operands
  1039.  
  1040. Performing a floating-point operation on a memory operand instead of on a stack register costs no cycles. In the integer part of the Pentium processor, it was better to avoid memory operands. In the floating-point part, you are encouraged to use memory operands.
  1041.  
  1042. 6.1.4 Floating-Point Stalls
  1043.  
  1044. There are cases where a delay occurs between two operations. Instructions should be inserted between the pair that cause the pipe stall. These instructions could be integer instructions or floating-point instructions that will not cause a new stall themselves. The number of instructions that should be inserted depends on the delay length.
  1045.  
  1046. One example of this is when a floating-point instruction depends on the result of the immediately preceding instruction which is also a floating-point instruction. In this case, it would be advantageous to move integer instructions between the two fp instructions, even if the integer instructions perform loop control. The following example restructures a loop in this manner:
  1047.  
  1048. for (i=0; i<Size; i++)
  1049.     array1 [i] += array2 [i];
  1050.  
  1051.  
  1052.            Pentium Processor         Intel486 Processor
  1053.            Clocks                     Clocks
  1054. TopOfLoop:
  1055.   flds   [eax + array2]    2 - AGI        3
  1056.   fadds  [eax + array1]    1        3
  1057.   fstps  [eax + array1]        5 - Wait for fadds    14 - Wait for fadds
  1058.   add    eax, 4        1        1
  1059.   jnz    TopOfLoop        0 - Pairs with add    3
  1060.                 ------                    ------
  1061.         9            24
  1062.  
  1063.  
  1064.  
  1065.                          Pentium Processor         Intel486 Processor
  1066.                               Clocks                     Clocks
  1067. TopOfLoop:
  1068.   fstps [eax + array1]    4 - Wait for fadds,AGI    10 - Wait for fadds
  1069. LoopEntryPoint:
  1070.   flds  [eax + array2]    1        3
  1071.   fadds [eax + array1]    1        3
  1072.   add eax, 4        1        1
  1073.   jnz TopOfLoop        0 - Pairs with add    3
  1074.         -------    -------
  1075.         7        20
  1076.  
  1077.  
  1078. By moving the integer instructions between the fadds and fstps, both processors can execute the integer instructions while the fadds is completing in the floating-point unit and before the fstps begins execution. Note that this new loop structure requires a separate entry point for the first iteration because the loop needs to begin with the flds. Also, there needs to be an additional fstps after the conditional jump to finish the final loop iteration.
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084. 1. Floating-Point Stores
  1085.  
  1086. A floating-point store must wait an extra cycle for its floating-point operand. After an fld, an fst must wait one clock. After the common arithmetic operations, fmul and fadd, which normally have a latency of two, fst waits an extra cycle for a total of three1.
  1087.  
  1088.     fld   meml    ; 1 fld takes 1 clock
  1089.         ; 2 fst waits, schedule something here
  1090.     fst   mem2    ; 3,4 fst takes 2 clocks
  1091.  
  1092.     fadd  meml    ; 1 add takes 3 clocks
  1093.         ; 2 add, schedule something here
  1094.         ; 3 add, schedule something here
  1095.         ; 4 fst waits, schedule something here
  1096.     fst   mem2    ; 5,2 fst takes 2 clocks
  1097.  
  1098. In the next example, the store is not dependent on the previous load:
  1099.  
  1100.     fld   meml          : 1
  1101.     fld   mem2          ; 2
  1102.     fxch  st(l)         ; 2
  1103.     fst   mem3          ; 3 stores values loaded from meml
  1104.  
  1105. 2. A register may be used immediately after it has been loaded (with fld).
  1106.  
  1107.     fld   mem1          ; l
  1108.     fadd  mem2          ; 2,3,4
  1109.  
  1110. 3. Use of a register by a floating-point operation immediately after it has been written by another fadd, fsub, or fmul causes a 2 cycle delay. If instructions are inserted between these two, then latency and a potential stall can be hidden.
  1111.  
  1112. 4. There are multi-cycle floating-point instructions (fdiv and fsqrt) that execute in the floating-point unit pipe. While executing these instructions in the floating-point unit pipe, integer instructions can be executed in parallel. Emitting a number of integer instructions after such an instruction will keep the integer execution units busy (the exact number of instructions depends on the floating-point instruction's cycle count).
  1113.  
  1114. 5. The integer multiply operations, mul and imul, are executed in the floating-point unit so these instructions cannot be executed in parallel with a floating-point instruction.
  1115.  
  1116. 6. A floating-point multiply instruction (fmul) delays for one cycle if the immediately preceding cycle executed an fmul or an fmul / fxch pair. The multiplier can only accept a new pair of operands every other cycle.
  1117.  
  1118. 7. Transcendental operations execute in the U pipe and nothing can be overlapped with them, so an integer instruction following such an instruction will wait until that instruction completes.
  1119.  
  1120. 8. Floating-point operations that take integer operands (fiadd or fisub ..) should be avoided. These instructions should be split into two instructions: fild and a floating-point operation. The number of cycles before another instruction can be issued (throughput) for fiadd is 4, while for fild and simple floating-point op it is 1.
  1121.  
  1122.  
  1123. Example:
  1124.  
  1125. Complex Instructions          Better for Potential Overlap
  1126.  
  1127. fiadd  [ebp] ; 4              fild   [ebp]  ; 1
  1128.                               faddp  st(l)  ; 2
  1129.  
  1130. Using the fild - faddp instructions yields 2 free cycles for executing other instructions.
  1131.  
  1132. 9. The fstsw instruction that usually appears after a floating-point comparison instruction (fcom, fcomp, fcompp) delays for 3 cycles. Other instructions may be inserted after the comparison instruction in order to hide the latency.
  1133.  
  1134. 10. Moving a floating-point memory/immediate to memory should be done by integer moves (if precision conversion is not needed) instead of doing fld - fstp.
  1135.  
  1136. Examples for floating-point moves:
  1137.  
  1138. double precision: 4 vs. 2 cycles
  1139.  
  1140.         fld  [ebp]     ; 1           mov  eax, [ebp]        ; 1
  1141.                        ; 2           mov  edx, [ebp+4]      ; 1
  1142.         fstp [edi]     ; 3,4         mov  [edi], eax        ; 2
  1143.                                      mov  [edi+4], edx      ; 2
  1144.  
  1145.     single precision: 4 vs. 2 cycles
  1146.  
  1147.             fld  [ebp]     ; 1           mov  eax, [ebp]        ; 1
  1148.                        ; 2           mov  [edi], eax        ; 2
  1149.         fstp [edi]     ; 3,4
  1150.  
  1151. This optimization also applies to the Intel486 processor.
  1152.  
  1153. 11. Transcendental operations execute on the Pentium processor much faster than on the Intel486 processor.  It may be worthwhile inlining some of these math library calls because of the fact that the call and prologue/epilogue overhead involved with the library calls is no longer negligible.  Emulating these operations in software will not be faster than the hardware unless accuracy is sacrificed.
  1154.  
  1155. 12. Integer instructions generally overlap with the floating-point operations except when the last
  1156. floating-point operation was fxch. In this case there is a one cycle delay.
  1157.  
  1158.     U pipe                   V  pipe        
  1159.  
  1160.     fadd                  fxch                           ; 1
  1161.                                                             ; 2 fxch delay
  1162.     mov   eax, 1          inc       edx                  ; 3
  1163.  
  1164.  
  1165. 7. Summary
  1166.  
  1167. The following tables summarize the micro architecture differences among Intel386, Intel486 and Pentium processors and the corresponding code generation consideration. It is possible to derive a set of code generation strategies that provide the optimal performance across the various members of the Intel386 processor family except for the use of FXCH to maximize the Pentium processor floating-point throughput  which can be implemented under a user-directed option.
  1168.  
  1169.  
  1170.  
  1171. Intel386TM Processor
  1172.  
  1173. Intel486TM  Processor
  1174.  
  1175. PentiumTM  Processor
  1176.  
  1177.  
  1178. Cache
  1179.  
  1180. None
  1181.  
  1182. 8K Combined
  1183.  
  1184. 8K Code, 8K Data
  1185.  
  1186.  
  1187. Prefetch
  1188.  
  1189. 4x4b filled by external memory access
  1190.  
  1191. 2x6b shared bus to cache
  1192.  
  1193. 4x32b private bus to cache
  1194.  
  1195.  
  1196. Decoder
  1197.  
  1198. 3 deep decoded FIFO
  1199.  
  1200. part of core pipeline
  1201.  
  1202. part of core pipeline
  1203.  
  1204.  
  1205. Core
  1206.  
  1207. some instruction overlap
  1208.  
  1209. 5 stages pipeline
  1210.  
  1211. 5 stages pipeline & superscalar
  1212.  
  1213.  
  1214. Math
  1215.  
  1216. Co-processor
  1217.  
  1218. On-Chip
  1219.  
  1220. On-Chip & pipelined
  1221.  
  1222.  
  1223.  
  1224.  
  1225. Processor Characteristics
  1226.  
  1227. Optimizations
  1228.  
  1229. Intel386 Processor
  1230.  
  1231. Intel486 Processor
  1232.  
  1233. Pentium Processor
  1234.  
  1235.  
  1236. Cache
  1237.  
  1238. Interleave mem with non-mem
  1239.  
  1240. don't care
  1241.  
  1242. Interleave if 4 consecutive
  1243.  
  1244. don't care
  1245.  
  1246.  
  1247. Prefetcher
  1248.  
  1249. Alignment
  1250.  
  1251. 0-MOD-4
  1252.  
  1253. 0-MOD-16
  1254.  
  1255. don't care
  1256.  
  1257.  
  1258. Pipelined Execution core
  1259.  
  1260. Base Vs index
  1261.  
  1262. don't care
  1263.  
  1264. use base
  1265.  
  1266. don't care
  1267.  
  1268.  
  1269.  
  1270.  
  1271. Avoid AGI
  1272.  
  1273. don't care
  1274.  
  1275. next instr
  1276.  
  1277. next 3 instr
  1278.  
  1279.  
  1280.  
  1281.  
  1282. Instruction selection
  1283.  
  1284. 1 clk penalty
  1285.  
  1286. short instr
  1287.  
  1288. short instr
  1289.  
  1290.  
  1291. Superscalar
  1292.  
  1293. Pairing
  1294.  
  1295. don't care
  1296.  
  1297. don't care
  1298.  
  1299. pair
  1300.  
  1301.  
  1302. Pipelined FPU with FXCH
  1303.  
  1304. more scheduling
  1305.  
  1306. 18 clk penalty
  1307.  
  1308. 4 clk penalty
  1309.  
  1310. schedule
  1311.  
  1312.  
  1313.  
  1314.  
  1315. Recommendations for Blended:
  1316.  
  1317. 1. Interleave mem with non-mem: do nothing
  1318.  
  1319. 2. Code alignment: 0-mod-16 on loop
  1320.  
  1321. 3. Base Vs index: use base
  1322.  
  1323. 4. Avoid AGI: next 3 instructions
  1324.  
  1325. 5. Instruction selection: short instructions sequence
  1326.  
  1327. 6. Pairing: pair
  1328.  
  1329. 7. FP scheduling: avoid FXCH
  1330.  
  1331. APPENDIX A
  1332. INSTRUCTION PAIRING SUMMARY
  1333.  
  1334.  
  1335. The following abbreviations are used in the Pairing column of the integer table in this Appendix:
  1336. NP    - Not pairable, executes in U pipe
  1337. PU    - Pairable if issued to U pipe
  1338. PV    - Pairable if issued to V pipe
  1339. UV    - Pairable in either pipe
  1340.  
  1341.  
  1342. In the floating-point table in this Appendix:
  1343. FX    - Pairs with FXCH
  1344. NP    - No pairing.
  1345.  
  1346. The I/O instructions are not pairable. 
  1347. Integer Instruction Pairing
  1348. INSTRUCTION    FORMAT
  1349.  
  1350. Pairing
  1351.  
  1352.  
  1353. AAA - ASCII Adjust after Addition
  1354.  
  1355. NP
  1356.  
  1357.  
  1358. AAD - ASCII Adjust AX before Division
  1359.  
  1360. NP
  1361.  
  1362.  
  1363. AAM - ASCII Adjust AX after Multiply
  1364.  
  1365. NP
  1366.  
  1367.  
  1368. AAS - ASCII Adjust AL after Subtraction
  1369.  
  1370. NP
  1371.  
  1372.  
  1373. ADC - ADD with Carry
  1374.  
  1375. PU
  1376.  
  1377.  
  1378. ADD - Add
  1379.  
  1380. UV
  1381.  
  1382.  
  1383. AND - Logical AND
  1384.  
  1385. UV
  1386.  
  1387.  
  1388. ARPL - Adjust RPL Field of Selector
  1389.  
  1390. NP
  1391.  
  1392.  
  1393. BOUND - Check Array Against Bounds
  1394.  
  1395. NP
  1396.  
  1397.  
  1398. BSF - Bit Scan Forward
  1399.  
  1400. NP
  1401.  
  1402.  
  1403. BSR - Bit Scan Reverse
  1404.  
  1405. NP
  1406.  
  1407.  
  1408. BSWAP - Byte Swap
  1409.  
  1410. NP
  1411.  
  1412.  
  1413. BT - Bit Test
  1414.  
  1415. NP
  1416.  
  1417.  
  1418. BTC - Bit Test and Complement
  1419.  
  1420. NP
  1421.  
  1422.  
  1423. BTR - Bit Test and Reset
  1424.  
  1425. NP
  1426.  
  1427.  
  1428. BTS - Bit Test and Set
  1429.  
  1430. NP
  1431.  
  1432.  
  1433. CALL - Call Procedure (in same segment)
  1434.  
  1435.  
  1436.  
  1437.  
  1438.    direct    1110 1000 : full displacement
  1439.  
  1440. PV
  1441.  
  1442.  
  1443.    register indirect    1111 1111 : 11 010 reg
  1444.  
  1445. NP
  1446.  
  1447.  
  1448.    memory indirect    1111 1111 : mod 010 r/m
  1449.  
  1450. NP
  1451.  
  1452.  
  1453. CALL - Call Procedure (in other segment)
  1454.  
  1455. NP
  1456.  
  1457.  
  1458. CBW - Convert Byte to Word 
  1459. CWDE - Convert Word to Doubleword
  1460.  
  1461. NP
  1462.  
  1463.  
  1464. CLC - Clear Carry Flag
  1465.  
  1466. NP
  1467.  
  1468.  
  1469. CLD - Clear Direction Flag
  1470.  
  1471. NP
  1472.  
  1473.  
  1474. CLI - Clear Interrupt Flag
  1475.  
  1476. NP
  1477.  
  1478.  
  1479. CLTS - Clear Task-Switched Flag in CR0
  1480.  
  1481. NP
  1482.  
  1483.  
  1484. CMC - Complement Carry Flag
  1485.  
  1486. NP
  1487.  
  1488.  
  1489. CMP - Compare Two Operands
  1490.  
  1491. UV
  1492.  
  1493.  
  1494. CMPS/CMPSB/CMPSW/CMPSD - Compare String Operands
  1495.  
  1496. NP
  1497.  
  1498.  
  1499. CMPXCHG - Compare and Exchange 
  1500.  
  1501. NP
  1502.  
  1503.  
  1504. CMPXCHG8B - Compare and Exchange 8 Bytes 
  1505.  
  1506. NP
  1507.  
  1508.  
  1509. CWD - Convert Word to Dword 
  1510. CDQ - Convert Dword to Qword
  1511.  
  1512. NP
  1513.  
  1514.  
  1515. DAA - Decimal Adjust AL after Addition
  1516.  
  1517. NP
  1518.  
  1519.  
  1520. DAS - Decimal Adjust AL after Subtraction
  1521.  
  1522. NP
  1523.  
  1524.  
  1525. DEC - Decrement by 1
  1526.  
  1527. UV
  1528.  
  1529.  
  1530. DIV - Unsigned Divide
  1531.  
  1532. NP
  1533.  
  1534.  
  1535. ENTER - Make Stack Frame for Procedure Parameters
  1536.  
  1537. NP
  1538.  
  1539.  
  1540. HLT - Halt
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546. Integer Instruction Pairing (Continued)
  1547. INSTRUCTION    FORMAT
  1548.  
  1549. Pairing
  1550.  
  1551.  
  1552. IDIV - Signed Divide
  1553.  
  1554. NP
  1555.  
  1556.  
  1557. IMUL - Signed Multiply
  1558.  
  1559. NP
  1560.  
  1561.  
  1562. INC - Increment by 1
  1563.  
  1564. UV
  1565.  
  1566.  
  1567. INT n - Interrupt Type n 
  1568.  
  1569. NP
  1570.  
  1571.  
  1572. INT - Single-Step Interrupt 3
  1573.  
  1574. NP
  1575.  
  1576.  
  1577. INTO - Interrupt 4 on Overflow
  1578.  
  1579. NP
  1580.  
  1581.  
  1582. INVD - Invalidate Cache
  1583.  
  1584. NP
  1585.  
  1586.  
  1587. INVLPG - Invalidate TLB Entry
  1588.  
  1589. NP
  1590.  
  1591.  
  1592. IRET/IRETD - Interrupt Return
  1593.  
  1594. NP
  1595.  
  1596.  
  1597. Jcc - Jump if Condition is Met
  1598.  
  1599. PV
  1600.  
  1601.  
  1602. JCXZ/JECXZ - Jump on CX/ECX Zero
  1603.  
  1604. NP
  1605.  
  1606.  
  1607. JMP - Unconditional Jump (to same segment)
  1608.  
  1609.  
  1610.  
  1611.  
  1612.    short    1110 1011 : 8-bit displacement
  1613.  
  1614. PV
  1615.  
  1616.  
  1617.    direct    1110 1001 : full displacement
  1618.  
  1619. PV
  1620.  
  1621.  
  1622.    register indirect    1111 1111 : 11 100 reg
  1623.  
  1624. NP
  1625.  
  1626.  
  1627.    memory indirect    1111 1111 : mod 100 r/m
  1628.  
  1629. NP
  1630.  
  1631.  
  1632. JMP - Unconditional Jump (to other segment)
  1633.  
  1634. NP
  1635.  
  1636.  
  1637. LAHF - Load Flags into AH Register
  1638.  
  1639. NP
  1640.  
  1641.  
  1642. LAR - Load Access Rights Byte
  1643.  
  1644. NP
  1645.  
  1646.  
  1647. LDS - Load Pointer to DS
  1648.  
  1649. NP
  1650.  
  1651.  
  1652. LEA - Load Effective Address
  1653.  
  1654. UV
  1655.  
  1656.  
  1657. LEAVE - High Level Procedure Exit
  1658.  
  1659. NP
  1660.  
  1661.  
  1662. LES - Load Pointer to ES 
  1663.  
  1664. NP
  1665.  
  1666.  
  1667. LFS - Load Pointer to FS 
  1668.  
  1669. NP
  1670.  
  1671.  
  1672. LGDT - Load Global Descriptor Table Register
  1673.  
  1674. NP
  1675.  
  1676.  
  1677. LGS - Load Pointer to GS 
  1678.  
  1679. NP
  1680.  
  1681.  
  1682. LIDT - Load Interrupt Descriptor Table Register
  1683.  
  1684. NP
  1685.  
  1686.  
  1687. LLDT - Load Local Descriptor Table Register
  1688.  
  1689. NP
  1690.  
  1691.  
  1692. LMSW - Load Machine Status Word
  1693.  
  1694. NP
  1695.  
  1696.  
  1697. LOCK - Assert LOCK# Signal Prefix
  1698.  
  1699.  
  1700.  
  1701.  
  1702. LODS/LODSB/LODSW/LODSD - Load String Operand
  1703.  
  1704. NP
  1705.  
  1706.  
  1707. LOOP - Loop Count 
  1708.  
  1709. NP
  1710.  
  1711.  
  1712. LOOPZ/LOOPE - Loop Count while Zero/Equal
  1713.  
  1714. NP
  1715.  
  1716.  
  1717. LOOPNZ/LOOPNE - Loop Count while not Zero/Equal
  1718.  
  1719. NP
  1720.  
  1721.  
  1722. LSL - Load Segment Limit
  1723.  
  1724. NP
  1725.  
  1726.  
  1727. LSS - Load Pointer to SS    0000 1111 : 1011 0010 : mod reg r/m
  1728.  
  1729. NP
  1730.  
  1731.  
  1732. LTR - Load Task Register
  1733.  
  1734. NP
  1735.  
  1736.  
  1737. MOV - Move Data
  1738.  
  1739. UV
  1740.  
  1741.  
  1742. MOV - Move to/from Control Registers
  1743.  
  1744. NP
  1745.  
  1746.  
  1747. MOV - Move to/from Debug Registers
  1748.  
  1749. NP
  1750.  
  1751.  
  1752.  
  1753. Integer Instruction Pairing (Continued)
  1754. INSTRUCTION    FORMAT
  1755.  
  1756. Pairing
  1757.  
  1758.  
  1759. MOV - Move to/from Segment Registers
  1760.  
  1761. NP
  1762.  
  1763.  
  1764. MOVS/MOVSB/MOVSW/MOVSD - Move Data from String to String
  1765.  
  1766. NP
  1767.  
  1768.  
  1769. MOVSX - Move with Sign-Extend
  1770.  
  1771. NP
  1772.  
  1773.  
  1774. MOVZX - Move with Zero-Extend
  1775.  
  1776. NP
  1777.  
  1778.  
  1779. MUL - Unsigned Multiplication of AL, AX or EAX
  1780.  
  1781. NP
  1782.  
  1783.  
  1784. NEG - Two's Complement Negation
  1785.  
  1786. NP
  1787.  
  1788.  
  1789. NOP - No Operation    1001 0000
  1790.  
  1791. UV
  1792.  
  1793.  
  1794. NOT - One's Complement Negation
  1795.  
  1796. NP
  1797.  
  1798.  
  1799. OR - Logical Inclusive OR
  1800.  
  1801. UV
  1802.  
  1803.  
  1804. POP - Pop a Word from the Stack
  1805.  
  1806.  
  1807.  
  1808.  
  1809.    reg    1000 1111 : 11 000 reg
  1810.  
  1811. UV
  1812.  
  1813.  
  1814.       or    0101 1 reg
  1815.  
  1816. UV
  1817.  
  1818.  
  1819.    memory    1000 1111 : mod 000 r/m
  1820.  
  1821. NP
  1822.  
  1823.  
  1824. POP - Pop a Segment Register from the Stack
  1825.  
  1826. NP
  1827.  
  1828.  
  1829. POPA/POPAD - Pop All General Registers
  1830.  
  1831. NP
  1832.  
  1833.  
  1834. POPF/POPFD - Pop Stack into FLAGS or EFLAGS Register
  1835.  
  1836. NP
  1837.  
  1838.  
  1839. PUSH - Push Operand onto the Stack
  1840.  
  1841.  
  1842.  
  1843.  
  1844.    reg    1111 1111 : 11 110 reg
  1845.  
  1846. UV
  1847.  
  1848.  
  1849.       or    0101 0 reg
  1850.  
  1851. UV
  1852.  
  1853.  
  1854.    memory    1111 1111 : mod 110 r/m
  1855.  
  1856. NP
  1857.  
  1858.  
  1859.    immediate    0110 10s0 : immediate data
  1860.  
  1861. UV
  1862.  
  1863.  
  1864. PUSH - Push Segment Register onto the Stack
  1865.  
  1866. NP
  1867.  
  1868.  
  1869. PUSHA/PUSHAD - Push All General Registers
  1870.  
  1871. NP
  1872.  
  1873.  
  1874. PUSHF/PUSHFD - Push Flags Register onto the Stack
  1875.  
  1876. NP
  1877.  
  1878.  
  1879. RCL - Rotate thru Carry Left
  1880.  
  1881.  
  1882.  
  1883.  
  1884.    reg by 1    1101 000w : 11 010 reg
  1885.  
  1886. PU
  1887.  
  1888.  
  1889.    memory by 1    1101 000w : mod 010 r/m
  1890.  
  1891. PU
  1892.  
  1893.  
  1894.    reg by CL    1101 001w : 11 010 reg
  1895.  
  1896. NP
  1897.  
  1898.  
  1899.    memory by CL    1101 001w : mod 010 r/m
  1900.  
  1901. NP
  1902.  
  1903.  
  1904.    reg by immediate count    1100 000w : 11 010 reg : imm8 data
  1905.  
  1906. PU
  1907.  
  1908.  
  1909.    memory by immediate count    1100 000w : mod 010 r/m : imm8 data
  1910.  
  1911. PU
  1912.  
  1913.  
  1914. RCR - Rotate thru Carry Right
  1915.  
  1916.  
  1917.  
  1918.  
  1919.    reg by 1    1101 000w : 11 011 reg
  1920.  
  1921. PU
  1922.  
  1923.  
  1924.    memory by 1    1101 000w : mod 011 r/m
  1925.  
  1926. PU
  1927.  
  1928.  
  1929.    reg by CL    1101 001w : 11 011 reg
  1930.  
  1931. NP
  1932.  
  1933.  
  1934.    memory by CL    1101 001w : mod 011 r/m
  1935.  
  1936. NP
  1937.  
  1938.  
  1939.    reg by immediate count    1100 000w : 11 011 reg : imm8 data
  1940.  
  1941. PU
  1942.  
  1943.  
  1944.    memory by immediate count    1100 000w : mod 011 r/m : imm8 data
  1945.  
  1946. PU
  1947.  
  1948.  
  1949. RDMSR - Read from Model-Specific Register
  1950.  
  1951. NP
  1952.  
  1953.  
  1954. REP LODS - Load String
  1955.  
  1956. NP
  1957.  
  1958.  
  1959.  
  1960. Integer Instruction Pairing (Continued)
  1961. INSTRUCTION    FORMAT
  1962.  
  1963. Pairing
  1964.  
  1965.  
  1966. REP MOVS - Move String
  1967.  
  1968. NP
  1969.  
  1970.  
  1971. REP STOS - Store String
  1972.  
  1973. NP
  1974.  
  1975.  
  1976. REPE CMPS - Compare String (Find Non-Match)
  1977.  
  1978. NP
  1979.  
  1980.  
  1981. REPE SCAS - Scan String (Find Non-AL/AX/EAX)
  1982.  
  1983. NP
  1984.  
  1985.  
  1986. REPNE CMPS - Compare String (Find Match)
  1987.  
  1988. NP
  1989.  
  1990.  
  1991. REPNE SCAS - Scan String (Find AL/AX/EAX)
  1992.  
  1993. NP
  1994.  
  1995.  
  1996. RET - Return from Procedure (to same segment)
  1997.  
  1998. NP
  1999.  
  2000.  
  2001. RET - Return from Procedure (to other segment)
  2002.  
  2003. NP
  2004.  
  2005.  
  2006. ROL - Rotate (not thru Carry) Left
  2007.  
  2008.  
  2009.  
  2010.  
  2011.    reg by 1    1101 000w : 11 000 reg
  2012.  
  2013. PU
  2014.  
  2015.  
  2016.    memory by 1    1101 000w : mod 000 r/m
  2017.  
  2018. PU
  2019.  
  2020.  
  2021.    reg by CL    1101 001w : 11 000 reg
  2022.  
  2023. NP
  2024.  
  2025.  
  2026.    memory by CL    1101 001w : mod 000 r/m
  2027.  
  2028. NP
  2029.  
  2030.  
  2031.    reg by immediate count    1100 000w : 11 000 reg : imm8 data
  2032.  
  2033. PU
  2034.  
  2035.  
  2036.    memory by immediate count    1100 000w : mod 000 r/m : imm8 data
  2037.  
  2038. PU
  2039.  
  2040.  
  2041. ROR - Rotate (not thru Carry) Right
  2042.  
  2043.  
  2044.  
  2045.  
  2046.    reg by 1    1101 000w : 11 001 reg
  2047.  
  2048. PU
  2049.  
  2050.  
  2051.    memory by 1    1101 000w : mod 001 r/m
  2052.  
  2053. PU
  2054.  
  2055.  
  2056.    reg by CL    1101 001w : 11 001 reg
  2057.  
  2058. NP
  2059.  
  2060.  
  2061.    memory by CL    1101 001w : mod 001 r/m
  2062.  
  2063. NP
  2064.  
  2065.  
  2066.    reg by immediate count    1100 000w : 11 001 reg : imm8 data
  2067.  
  2068. PU
  2069.  
  2070.  
  2071.    memory by immediate count    1100 000w : mod 001 r/m : imm8 data
  2072.  
  2073. PU
  2074.  
  2075.  
  2076. RSM - Resume from System  Management Mode
  2077.  
  2078. NP
  2079.  
  2080.  
  2081. SAHF - Store AH into Flags
  2082.  
  2083. NP
  2084.  
  2085.  
  2086. SAL - Shift Arithmetic Left    same instruction as SHL
  2087.  
  2088.  
  2089.  
  2090.  
  2091. SAR - Shift Arithmetic Right
  2092.  
  2093.  
  2094.  
  2095.  
  2096.    reg by 1    1101 000w : 11 111 reg
  2097.  
  2098. PU
  2099.  
  2100.  
  2101.    memory by 1    1101 000w : mod 111 r/m
  2102.  
  2103. PU
  2104.  
  2105.  
  2106.    reg by CL    1101 001w : 11 111 reg
  2107.  
  2108. NP
  2109.  
  2110.  
  2111.    memory by CL    1101 001w : mod 111 r/m
  2112.  
  2113. NP
  2114.  
  2115.  
  2116.    reg by immediate count    1100 000w : 11 111 reg : imm8 data
  2117.  
  2118. PU
  2119.  
  2120.  
  2121.    memory by immediate count    1100 000w : mod 111 r/m : imm8 data
  2122.  
  2123. PU
  2124.  
  2125.  
  2126. SBB - Integer Subtraction with Borrow
  2127.  
  2128. PU
  2129.  
  2130.  
  2131. SCAS/SCASB/SCASW/SCASD - Scan String
  2132.  
  2133. NP
  2134.  
  2135.  
  2136. SETcc - Byte Set on Condition
  2137.  
  2138. NP
  2139.  
  2140.  
  2141. SGDT - Store Global Descriptor Table Register
  2142.  
  2143. NP
  2144.  
  2145.  
  2146.  
  2147. Integer Instruction Pairing (Continued)
  2148. INSTRUCTION    FORMAT
  2149.  
  2150. Pairing
  2151.  
  2152.  
  2153. SHL - Shift Left
  2154.  
  2155.  
  2156.  
  2157.  
  2158.    reg by 1    1101 000w : 11 100 reg
  2159.  
  2160. PU
  2161.  
  2162.  
  2163.    memory by 1    1101 000w : mod 100 r/m
  2164.  
  2165. PU
  2166.  
  2167.  
  2168.    reg by CL    1101 001w : 11 100 reg
  2169.  
  2170. NP
  2171.  
  2172.  
  2173.    memory by CL    1101 001w : mod 100 r/m
  2174.  
  2175. NP
  2176.  
  2177.  
  2178.    reg by immediate count    1100 000w : 11 100 reg : imm8 data
  2179.  
  2180. PU
  2181.  
  2182.  
  2183.    memory by immediate count    1100 000w : mod 100 r/m : imm8 data
  2184.  
  2185. PU
  2186.  
  2187.  
  2188. SHLD - Double Precision Shift Left
  2189.  
  2190.  
  2191.  
  2192.  
  2193.    register by immediate count    0000 1111 : 1010 0100 : 11 reg2 reg1 : imm8
  2194.  
  2195. NP
  2196.  
  2197.  
  2198.    memory by immediate count    0000 1111 : 1010 0100 : mod reg r/m : imm8
  2199.  
  2200. NP
  2201.  
  2202.  
  2203.    register by CL    0000 1111 : 1010 0101 : 11 reg2 reg1
  2204.  
  2205. NP
  2206.  
  2207.  
  2208.    memory by CL    0000 1111 : 1010 0101 : mod reg r/m
  2209.  
  2210. NP
  2211.  
  2212.  
  2213. SHR - Shift Right
  2214.  
  2215.  
  2216.  
  2217.  
  2218.    reg by 1    1101 000w : 11 101 reg
  2219.  
  2220. PU
  2221.  
  2222.  
  2223.    memory by 1    1101 000w : mod 101 r/m
  2224.  
  2225. PU
  2226.  
  2227.  
  2228.    reg by CL    1101 001w : 11 101 reg
  2229.  
  2230. NP
  2231.  
  2232.  
  2233.    memory by CL    1101 001w : mod 101 r/m
  2234.  
  2235. NP
  2236.  
  2237.  
  2238.    reg by immediate count    1100 000w : 11 101 reg : imm8 data
  2239.  
  2240. PU
  2241.  
  2242.  
  2243.    memory by immediate count    1100 000w : mod 101 r/m : imm8 data
  2244.  
  2245. PU
  2246.  
  2247.  
  2248. SHRD - Double Precision Shift Right
  2249.  
  2250.  
  2251.  
  2252.  
  2253.    register by immediate count    0000 1111 : 1010 1100 : 11 reg2 reg1 : imm8
  2254.  
  2255. NP
  2256.  
  2257.  
  2258.    memory by immediate count    0000 1111 : 1010 1100 : mod reg r/m : imm8
  2259.  
  2260. NP
  2261.  
  2262.  
  2263.    register by CL    0000 1111 : 1010 1101 : 11 reg2 reg1
  2264.  
  2265. NP
  2266.  
  2267.  
  2268.    memory by CL    0000 1111 : 1010 1101 : mod reg r/m
  2269.  
  2270. NP
  2271.  
  2272.  
  2273. SIDT - Store Interrupt Descriptor Table Register
  2274.  
  2275. NP
  2276.  
  2277.  
  2278. SLDT - Store Local Descriptor Table Register
  2279.  
  2280. NP
  2281.  
  2282.  
  2283. SMSW - Store Machine Status Word
  2284.  
  2285. NP
  2286.  
  2287.  
  2288. STC - Set Carry Flag
  2289.  
  2290. NP
  2291.  
  2292.  
  2293. STD - Set Direction Flag
  2294.  
  2295. NP
  2296.  
  2297.  
  2298. STI - Set Interrupt Flag
  2299.  
  2300.  
  2301.  
  2302.  
  2303. STOS/STOSB/STOSW/STOSD - Store String Data
  2304.  
  2305. NP
  2306.  
  2307.  
  2308. STR - Store Task Register
  2309.  
  2310. NP
  2311.  
  2312.  
  2313. SUB - Integer Subtraction
  2314.  
  2315. UV
  2316.  
  2317.  
  2318. TEST - Logical Compare
  2319.  
  2320.  
  2321.  
  2322.  
  2323.    reg1 and reg2    1000 010w : 11 reg1 reg2
  2324.  
  2325. UV
  2326.  
  2327.  
  2328.    memory and register    1000 010w : mod reg r/m
  2329.  
  2330. UV
  2331.  
  2332.  
  2333.    immediate and register    1111 011w : 11 000 reg : immediate data
  2334.  
  2335. NP
  2336.  
  2337.  
  2338.    immediate and accumulator    1010 100w : immediate data
  2339.  
  2340. UV
  2341.  
  2342.  
  2343.    immediate and memory    1111 011w : mod 000 r/m : immediate data
  2344.  
  2345. NP
  2346.  
  2347.  
  2348.  
  2349. Integer Instruction Pairing (Continued)
  2350. INSTRUCTION    FORMAT
  2351.  
  2352. Pairing
  2353.  
  2354.  
  2355. VERR - Verify a Segment for Reading 
  2356.  
  2357. NP
  2358.  
  2359.  
  2360. VERW - Verify a Segment for Writing
  2361.  
  2362. NP
  2363.  
  2364.  
  2365. WAIT - Wait    1001 1011
  2366.  
  2367. NP
  2368.  
  2369.  
  2370. WBINVD - Write-Back and Invalidate Data Cache
  2371.  
  2372. NP
  2373.  
  2374.  
  2375. WRMSR - Write to Model-Specific Register
  2376.  
  2377. NP
  2378.  
  2379.  
  2380. XADD - Exchange and Add
  2381.  
  2382. NP
  2383.  
  2384.  
  2385. XCHG - Exchange Register/Memory with Register
  2386.  
  2387. NP
  2388.  
  2389.  
  2390. XLAT/XLATB - Table Look-up Translation
  2391.  
  2392. NP
  2393.  
  2394.  
  2395. XOR - Logical Exclusive OR
  2396.  
  2397. UV
  2398.  
  2399.  
  2400.  
  2401. Floating-Point Instruction Pairing
  2402. INSTRUCTION    FORMAT
  2403.  
  2404. Pairing
  2405.  
  2406.  
  2407. F2XM1 - Compute 2ST(0) - 1
  2408.  
  2409. NP
  2410.  
  2411.  
  2412. FABS - Absolute Value
  2413.  
  2414. FX
  2415.  
  2416.  
  2417. FADD - Add
  2418.  
  2419. FX
  2420.  
  2421.  
  2422. FADDP - Add and Pop
  2423.  
  2424. FX
  2425.  
  2426.  
  2427. FBLD - Load Binary Coded Decimal
  2428.  
  2429. NP
  2430.  
  2431.  
  2432. FBSTP - Store Binary Coded Decimal and Pop
  2433.  
  2434. NP
  2435.  
  2436.  
  2437. FCHS - Change Sign
  2438.  
  2439. FX
  2440.  
  2441.  
  2442. FCLEX - Clear Exceptions
  2443.  
  2444. NP
  2445.  
  2446.  
  2447. FCOM - Compare Real
  2448.  
  2449. FX
  2450.  
  2451.  
  2452. FCOMP - Compare Real and Pop
  2453.  
  2454. FX
  2455.  
  2456.  
  2457. FCOMPP - Compare Real and Pop Twice
  2458.  
  2459.  
  2460.  
  2461.  
  2462. FCOS - Cosine of ST(0)
  2463.  
  2464. NP
  2465.  
  2466.  
  2467. FDECSTP - Decrement Stack-Top Pointer
  2468.  
  2469. NP
  2470.  
  2471.  
  2472. FDIV - Divide
  2473.  
  2474. FX
  2475.  
  2476.  
  2477. FDIVP - Divide and Pop
  2478.  
  2479. FX
  2480.  
  2481.  
  2482. FDIVR - Reverse Divide
  2483.  
  2484. FX
  2485.  
  2486.  
  2487. FDIVRP - Reverse Divide and Pop
  2488.  
  2489. FX
  2490.  
  2491.  
  2492. FFREE - Free ST(i) Register
  2493.  
  2494. NP
  2495.  
  2496.  
  2497. FIADD - Add Integer
  2498.  
  2499. NP
  2500.  
  2501.  
  2502. FICOM - Compare Integer
  2503.  
  2504. NP
  2505.  
  2506.  
  2507. FICOMP - Compare Integer and Pop
  2508.  
  2509. NP
  2510.  
  2511.  
  2512. FIDIV
  2513.  
  2514. NP
  2515.  
  2516.  
  2517. FIDIVR
  2518.  
  2519. NP
  2520.  
  2521.  
  2522. FILD - Load Integer
  2523.  
  2524. NP
  2525.  
  2526.  
  2527. FIMUL
  2528.  
  2529. NP
  2530.  
  2531.  
  2532. FINCSTP - Increment Stack Pointer
  2533.  
  2534. NP
  2535.  
  2536.  
  2537. FINIT - Initialize Floating-Point Unit
  2538.  
  2539. NP
  2540.  
  2541.  
  2542. FIST - Store Integer
  2543.  
  2544. NP
  2545.  
  2546.  
  2547. FISTP - Store Integer and Pop
  2548.  
  2549. NP
  2550.  
  2551.  
  2552. FISUB
  2553.  
  2554. NP
  2555.  
  2556.  
  2557. FISUBR
  2558.  
  2559. NP
  2560.  
  2561.  
  2562. FLD - Load Real
  2563.  
  2564.  
  2565.  
  2566.  
  2567.    32-bit memory    11011 001 : mod 000 r/m
  2568.  
  2569. FX
  2570.  
  2571.  
  2572.    64-bit memory    11011 101 : mod 000 r/m
  2573.  
  2574. FX
  2575.  
  2576.  
  2577.    80-bit memory    11011 011 : mod 101 r/m
  2578.  
  2579. NP
  2580.  
  2581.  
  2582.    ST(i)    11011 001 : 11 000 ST(i)
  2583.  
  2584. FX
  2585.  
  2586.  
  2587. FLD1 - Load +1.0 into ST(0)
  2588.  
  2589. NP
  2590.  
  2591.  
  2592. FLDCW - Load Control Word
  2593.  
  2594. NP
  2595.  
  2596.  
  2597. FLDENV - Load FPU Environment
  2598.  
  2599. NP
  2600.  
  2601.  
  2602. FLDL2E - Load log2() into ST(0)
  2603.  
  2604. NP
  2605.  
  2606.  
  2607. FLDL2T - Load log2(10) into ST(0)
  2608.  
  2609. NP
  2610.  
  2611.  
  2612.  
  2613. Floating-Point Instruction Pairing (Continued)
  2614. INSTRUCTION    FORMAT
  2615.  
  2616. Pairing
  2617.  
  2618.  
  2619. FLDLG2 - Load log10(2) into ST(0)
  2620.  
  2621. NP
  2622.  
  2623.  
  2624. FLDLN2 - Load log(2) into ST(0)
  2625.  
  2626. NP
  2627.  
  2628.  
  2629. FLDPI - Load  into ST(0)
  2630.  
  2631. NP
  2632.  
  2633.  
  2634. FLDZ - Load +0.0 into ST(0)
  2635.  
  2636. NP
  2637.  
  2638.  
  2639. FMUL - Multiply
  2640.  
  2641. FX
  2642.  
  2643.  
  2644. FMULP - Multiply
  2645.  
  2646. FX
  2647.  
  2648.  
  2649. FNOP - No Operation
  2650.  
  2651. NP
  2652.  
  2653.  
  2654. FPATAN - Partial Arctangent
  2655.  
  2656. NP
  2657.  
  2658.  
  2659. FPREM - Partial Remainder
  2660.  
  2661. NP
  2662.  
  2663.  
  2664. FPREM1 - Partial Remainder (IEEE)
  2665.  
  2666. NP
  2667.  
  2668.  
  2669. FPTAN - Partial Tangent
  2670.  
  2671. NP
  2672.  
  2673.  
  2674. FRNDINT - Round to Integer
  2675.  
  2676.  
  2677.  
  2678.  
  2679. FRSTOR - Restore FPU State
  2680.  
  2681. NP
  2682.  
  2683.  
  2684. FSAVE - Store FPU State
  2685.  
  2686. NP
  2687.  
  2688.  
  2689. FSCALE - Scale
  2690.  
  2691. NP
  2692.  
  2693.  
  2694. FSIN - Sine
  2695.  
  2696. NP
  2697.  
  2698.  
  2699. FSINCOS - Sine and Cosine
  2700.  
  2701. NP
  2702.  
  2703.  
  2704. FSQRT - Square Root
  2705.  
  2706. NP
  2707.  
  2708.  
  2709. FST - Store Real
  2710.  
  2711. NP
  2712.  
  2713.  
  2714. FSTCW - Store Control Word
  2715.  
  2716. NP
  2717.  
  2718.  
  2719. FSTENV - Store FPU Environment
  2720.  
  2721. NP
  2722.  
  2723.  
  2724. FSTP - Store Real and Pop
  2725.  
  2726. NP
  2727.  
  2728.  
  2729. FSTSW - Store Status Word into AX
  2730.  
  2731. NP
  2732.  
  2733.  
  2734. FSTSW - Store Status Word into Memory
  2735.  
  2736. NP
  2737.  
  2738.  
  2739. FSUB - Subtract
  2740.  
  2741. FX
  2742.  
  2743.  
  2744. FSUBP - Subtract and Pop
  2745.  
  2746. FX
  2747.  
  2748.  
  2749. FSUBR - Reverse Subtract
  2750.  
  2751. FX
  2752.  
  2753.  
  2754. FSUBRP - Reverse Subtract and Pop
  2755.  
  2756. FX
  2757.  
  2758.  
  2759. FTST - Test
  2760.  
  2761. FX
  2762.  
  2763.  
  2764. FUCOM - Unordered Compare Real)
  2765.  
  2766. FX
  2767.  
  2768.  
  2769. FUCOMP - Unordered Compare and Pop
  2770.  
  2771. FX
  2772.  
  2773.  
  2774. FUCOMPP - Unordered Compare  and Pop Twice
  2775.  
  2776. FX
  2777.  
  2778.  
  2779. FXAM - Examine
  2780.  
  2781. NP
  2782.  
  2783.  
  2784. FXCH - Exchange ST(0) and ST(i)
  2785.  
  2786.  
  2787.  
  2788.  
  2789. FXTRACT - Extract Exponent  and Significand
  2790.  
  2791. NP
  2792.  
  2793.  
  2794. FYL2X - ST(1)  log2(ST(0))
  2795.  
  2796. NP
  2797.  
  2798.  
  2799. FYL2XP1 - ST(1)  log2(ST(0) + 1.0)
  2800.  
  2801. NP
  2802.  
  2803.  
  2804. FWAIT - Wait until FPU Ready
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811. 1  This set includes also the faddp, fsubrp, ... instructions
  2812.  
  2813.     
  2814.  
  2815. Optimizations for Intel's 32-Bit Processors                                                               Version 2.0
  2816.  
  2817.                                                                             Page  26
  2818.  
  2819. Intel Confidential        Page 3
  2820.  
  2821.     Instruction Pairing Summary    
  2822.  
  2823.  
  2824.  
  2825.  
  2826.     A-9
  2827.  
  2828.     A-1
  2829.  
  2830.  
  2831.